package com.security.domain;

import java.util.ArrayList;
import java.util.Collection;

import javax.persistence.Entity;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

@Entity
public class CustomUserDetails extends FBSubject implements UserDetails {
	private static final long serialVersionUID = 1L;
	
	private String username;
	private String password;
	
	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		// 根据自定义逻辑来返回用户权限，如果用户权限返回空或者和拦截路径对应权限不同，验证不通过  
		Collection<SimpleGrantedAuthority> list = new ArrayList<SimpleGrantedAuthority>();  
		SimpleGrantedAuthority au = new SimpleGrantedAuthority("ROLE_USER");  
		SimpleGrantedAuthority admin = new SimpleGrantedAuthority("ROLE_ADMIN");  
		list.add(au);
		list.add(admin);
		return list;
	}


	@Override
	public String getPassword() {
		return this.password;
	}

	@Override
	public String getUsername() {
		return this.username;
	}

	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	public boolean isEnabled() {
		return true;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
}
